﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Runtime.InteropServices;
using System.Text;
using EntreeServer.Module;
using EntreeServer.Module.ActionTray;
using ME.SDK.SampleTheme.Controls;

namespace ME.SDK.TestApplications
{
    [Guid("a2faf6a6-69d9-42c0-920d-88a93c0b47ef")]
    public class TilesAndActions : EntreeApplication
    {

        public override string PluginPath
        {
            get
            {
                return "/_layouts/images/ME.SDK.TestApplications/TilesAndActions";
            }
        }

        public override void QueryList(EntreeScopeObject EntreeScope, EntreeListObject output)
        {
            #region Add Tiles
            Tiles TileSection = null;
            Tile aTile = null;
            EntreeListGroup grp = output.AddListGroup("My Tiles");
            grp.Collapsible = true;

            // Create Tile Secion
            TileSection = grp.AddListItem<Tiles>();
            // Create a Tile
            aTile = new Tile()
            {
                Title = "First"
            };
            // Add a ClickAction to the tile
            aTile.ClickAction = new EntreeClickActionObject(this);
            aTile.ClickAction["screen"] = "2";
            TileSection.TileCollection.Add(aTile);

            // Create a second tile
            aTile = new Tile()
            {
                Title = "Second",
                IconUrl = "/_layouts/images/EntreeServer/inc/at/at-checkin-64.png"
            };
            aTile.ClickAction = new EntreeClickActionObject(this);
            aTile.ClickAction["screen"] = "2";
            TileSection.TileCollection.Add(aTile);
            #endregion

            #region Handle Tile Clicks
            // Handle Click Events from the first 2 tiles
            if (EntreeScope.Properties.ContainsKey("screen") && EntreeScope.Properties["screen"] == "2")
            {
                EntreeListGroup g2 = output.AddListGroup("Additional");

                TileSection = g2.AddListItem<Tiles>();
                for (int i = 0; i < 9; i++)
                {
                    aTile = new Tile()
                    {
                        Title = "Dynamic " + i.ToString(),
                        IconUrl = "/_layouts/images/EntreeServer/inc/at/at-cancel-64.png"
                    };
                    aTile.ClickAction = new EntreeClickActionObject(this);
                    aTile.ClickAction["screen"] = "1";
                    TileSection.TileCollection.Add(aTile);
                }
            }
            #endregion

            #region Add Action Items
            ActionItem ai = null;
            ActionLane al = new ActionLane("CustomActions");
            al.ItemStyle = EntreeActionLaneStyles.text_only;

            //Create an Action with local app ClickAction
            ai = new ActionItem();
            ai.ActionId = "Action1";
            ai.Title = "Action 1";
            ai.ClickAction = new EntreeClickActionObject(this);
            ai.ClickAction["screen"] = "1";
            al.ActionItems.Items.Add(ai);

            //Create an Action with a Go To URL Click Action
            ai = new ActionItem();
            ai.ActionId = "Action2";
            ai.Title = "Action 2";
            ai.ClickAction = new EntreeGoToClickAction()
            {
                GoToUrl = "http://www.bing.com"
            };
            al.ActionItems.Items.Add(ai);

            output.ActionTray.ActionLanes.Items.Add(al);

            #endregion
        }

        public override string Title
        {
            get { return "Tiles And Actions"; }
        }
    }
}
